Create a DatabaseSeeder service with seed() methods that use idempotent checks before inserting. Run it via OnApplicationBootstrap in non-production environments or as a standalone NestJS application context invoked by a separate CLI script. Idempotency prevents re-seeding on restart.
Always make seed() idempotent — check existence before inserting so re-runs are safe.
Guard production seeding with a NODE_ENV check or a dedicated SEED_DATABASE flag.
NestFactory.createApplicationContext() creates a minimal app without starting the HTTP server — perfect for scripts.
Use bcrypt to hash seed passwords — never store plain text even in development data.
Place seed scripts in a seeds/ directory and add them to package.json scripts for easy invocation.